<%
=begin
apps: redis
platforms: kubernetes, tanzu-application-catalog
id: backup_restore
title: Backup and restore Redis deployments
category: administration
weight: 50
=end %>

To backup and restore Redis deployments on Kubernetes, you will need to create a snapshot of the data in the source cluster, and later restore it in a new cluster with the new parameters. Follow the instructions below:

### Step 1: Backup the deployment

* Connect to one of the nodes and start the Redis CLI tool. Then, run the commands below:

        $ kubectl exec -it my-redis-master-0 bash
        $ redis-cli
        127.0.0.1:6379> auth your_current_redis_password
        OK
        127.0.0.1:6379> save
        OK

* Copy the dump file from the Redis node:

        $ kubectl cp my-redis-master-0:/data/dump.rdb dump.rdb -c redis

### Step 2: Restore the data on the destination cluster

To restore the data in a new cluster, you will need to create a PVC and then upload the *dump.rdb* file to the new volume.

Follow the following steps:

* In the [*values.yaml*](https://github.com/bitnami/charts/blob/ae086acff0dd7c4f4b3101ebf1a7328e6a8ddcf5/bitnami/redis/values.yaml#L131) file set the *appendonly* parameter to *no*. You can skip this step if it is already configured as *no*

        commonConfiguration: |-
           # Enable AOF https://redis.io/topics/persistence#append-only-file
           appendonly no
           # Disable RDB persistence, AOF persistence already enabled.
           save ""

    > *Note that the `Enable AOF` comment belongs to the original config file and what you're actually doing is disabling it. This change will only be neccessary for the temporal cluster you're creating to upload the dump.*

* Start the new cluster to create the PVCs. Use the command below as an example:

        $ helm install new-redis  -f values.yaml .  --set cluster.enabled=true  --set cluster.slaveCount=3

* Now that the PVC were created, stop it and copy the *dump.rdp* file on the persisted data by using a helping pod.

        $ helm delete new-redis

        $ kubectl run --generator=run-pod/v1 -i --rm --tty volpod --overrides='
        {
            "apiVersion": "v1",
            "kind": "Pod",
            "metadata": {
                "name": "redisvolpod"
            },
            "spec": {
                "containers": [{
                   "command": [
                        "tail",
                        "-f",
                        "/dev/null"
                   ],
                   "image": "bitnami/minideb",
                   "name": "mycontainer",
                   "volumeMounts": [{
                       "mountPath": "/mnt",
                       "name": "redisdata"
                    }]
                }],
                "restartPolicy": "Never",
                "volumes": [{
                    "name": "redisdata",
                    "persistentVolumeClaim": {
                        "claimName": "redis-data-new-redis-master-0"
                    }
                }]
            }
        }' --image="bitnami/minideb"

        $ kubectl cp dump.rdb redisvolpod:/mnt/dump.rdb
        $ kubectl delete pod volpod

* Restart the cluster:

    > **INFO:** The *appendonly* parameter can be safely restored to your desired value.

        $ helm install new-redis  -f values.yaml .  --set cluster.enabled=true  --set cluster.slaveCount=3
